import axios from "axios";
import { createPinia } from "pinia";

import { defineStore } from "pinia";
import { nanoid } from "nanoid";
import { reactive } from "vue";
import { type QinghuaList } from '@/types/qinghua';

export const useTalkSetupStore = defineStore('talk-setup', () => {

    //在语法糖里定义的变量才具有响应式
    let list:QinghuaList = reactive([]);

    let s = localStorage.getItem("TalkMain-Setup") as string

    // console.log(s,"s");

    let d = JSON.parse(s)

    // console.log(d,"d");
    
    if(d != null){
        Object.assign(list,d);
    }

    // if(JSON.parse()){
    //     list = reactive(JSON.parse(localStorage.getItem("TalkMain-Setup"))._object.list)
    // }
    // else{
    //     let list = []
    // }
    // let list =  ?  as string) : [];

    async function getlist() {
        const res = await axios.get("https://api.uomg.com/api/rand.qinghua?format=json")

        let { data: { content } } = res;

        let obj = {
            id: nanoid(),
            content
        }
        // let obj1 = {
        //     id: nanoid(),
        //     content:"ddd"+nanoid()
        // }

        list.push(obj)

        
    }

    return {
        list,
        getlist
    }
})